package com.example.demo.plugins.mybatisplus;

import org.apache.ibatis.reflection.MetaObject;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;

public class TimeFillHandler extends MetaObjectHandler
{

	@Override
	public void insertFill(MetaObject metaObject) {// 更多查看源码测试用例
		setFieldValByName("createdAt", getCurrentTime(), metaObject);//mybatis-plus版本2.0.9+
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		setFieldValByName("updatedAt", getCurrentTime(), metaObject);
	}

	private Integer getCurrentTime() {
		long currentTimeMillis = System.currentTimeMillis();
		return (int) (currentTimeMillis / 1000);
	}

}
